package gather;

import java.util.ArrayList;

/*定义Java bean 类，Phone,属性：品牌价格
main方法定义集合存三个对象，小米1000，苹果8000，锤子2999
定义方法将价格低于3000的手机信息返回
 */
public class G8 {
    public static void main(String[] args) {
        //创建集合对象
        ArrayList<Phone> list = new ArrayList<>();
        //创建手机对象
        Phone p1 = new Phone("小米",1000);
        Phone p2 = new Phone("苹果",8000);
        Phone p3 = new Phone("锤子",2999);
        //添加数据
        list.add(p1);
        list.add(p2);
        list.add(p3);
        //调用方法
        ArrayList<Phone> phone = getPhone(list);
        for (int i = 0; i < phone.size(); i++) {
            Phone phones=phone.get(i);
            System.out.println(phones.getBrand()+","+phones.getPrice());
        }


    }
    public static ArrayList<Phone> getPhone(ArrayList<Phone> list){
        ArrayList<Phone> result = new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            Phone p= list.get(i);
            int price = p.getPrice();
            if(price < 3000){
                result.add(p);
            }
        }
        return result;
    }

}
